package offer;

public class 连续子数组的最大和42 {

    public static void main(String[] args) {
        int[] nums = {1,-2,3,10,-4,7,2,-5};
        System.out.println(maxSubArray(nums));
    }

    static int maxSubArray(int[] nums) {
        int res = nums[0];
        for(int i = 1; i < nums.length; i++) {
            //
            nums[i] += Math.max(nums[i - 1], 0);
            res = Math.max(res, nums[i]);
        }
        return res;
    }
}
